<template>
    <a-spin :spinning="loading.isSubmit">
        <a-card>
            <div class="table-page-search-wrapper">
                <TitleName title="基本信息" />
                <a-form-model
                        ref="form"
                        :model="form"
                        hide-required-mark
                        :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                        :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                >
                    <a-row :gutter="24">
                        <a-col
                                :md="16"
                                :sm="16"
                        >
                            <a-form-model-item
                                    label="所属单位"
                                    prop="projectId"
                            >
                                <org-tree-select
                                        v-model="form.projectId"
                                        is-auto-select-first
                                        is-need-auth
                                        check-strictly
                                        disabled
                                        :status-set="[1,2,3,4,5,6]"
                                        @select="selectOrg"
                                />
                            </a-form-model-item>
                        </a-col>
                        <a-col
                                :md="8"
                                :sm="8"
                        >
                            <a-form-model-item
                                    label="填报类型"
                                    prop="reportingType"
                            >
                                <a-select
                                        v-model="form.reportingType"
                                        placeholder="请选择"
                                        disabled
                                >
                                    <a-select-option value="0">
                                        计划内填报
                                    </a-select-option>
                                    <a-select-option value="1">
                                        计划外填报
                                    </a-select-option>
                                </a-select>
                            </a-form-model-item>
                        </a-col>
                        <a-col
                                v-if="form.reportingType == '0' && type!== 'view'"
                                :md="8"
                                :sm="8"
                                class="planSelection-class"
                        >
                            <a-form-model-item
                                    label="方案名称"
                                    prop="schemeName"
                                    required
                            >
                                <BaseInput
                                        v-model="form.schemeName"
                                        disabled
                                />
                            </a-form-model-item>
                        </a-col>
                        <a-col
                                v-else
                                :md="8"
                                :sm="8"
                        >
                            <a-form-model-item
                                    label="方案名称"
                                    prop="schemeName"
                                    required
                            >
                                <BaseInput
                                        v-model="form.schemeName"
                                        disabled
                                />
                            </a-form-model-item>
                        </a-col>
                        <a-col
                                :md="8"
                                :sm="8"
                        >
                            <a-form-model-item
                                    label="方案类型"
                                    prop="programTypeId"
                                    required
                            >
                                <a-select
                                        v-model="form.programTypeId"
                                        placeholder="请选择"
                                        disabled
                                >
                                    <a-select-option
                                            v-for="item in typeOption"
                                            :key="item.id"
                                            :value="item.id"
                                    >
                                        {{ item.name }}
                                    </a-select-option>
                                </a-select>
                            </a-form-model-item>
                        </a-col>
                        <a-col
                                :md="8"
                                :sm="8"
                        >
                            <a-form-model-item
                                    label="工程类别"
                                    prop="projectQualityTypeId"
                                    required
                            >
                                <SelectProjectType v-model="form.projectQualityTypeId" :defaultCheck="addtable" disabled></SelectProjectType>
                            </a-form-model-item>
                        </a-col>
                        <!-- 只有A/B类方案才有该字段 -->
                        <a-col
                                :md="24"
                                :sm="24"
                                v-if="schemeAB">
                            <a-form-model-item
                                    label="危大工程范围"
                                    prop="dangerDangerDTOS"
                                    required
                            >
                                <a-tag v-for="dangerProject in form.dangerDangerDTOS" :key="dangerProject.dangerProjectTypeId" class="mb10" color="#108ee9"  :closable="!(changeEditable || allDisable || !form.projectQualityTypeId)" @close="delDangerProjectType(dangerProject.dangerProjectTypeId)"><Ellipsis :length="50" tooltip>{{ dangerProject.dangerProjectTypeName }}</Ellipsis></a-tag>
                            </a-form-model-item>
                        </a-col>
                        <a-col
                                :md="8"
                                :sm="8"
                        >
                            <a-form-model-item
                                    prop="partIdList"
                                    label="分部分项"
                            >
                                <SelectTreeSubItem
                                        v-model="form.partIdList"
                                        disabled
                                        :typeId="form.projectQualityTypeId"
                                        :isMultiple="true"
                                        :fatherDisabled="true"
                                />
                            </a-form-model-item>
                        </a-col>

                        <a-col
                                :md="8"
                                :sm="8"
                        >
                            <a-form-model-item
                                    label="现行版本"
                                    prop="currentVersion"
                            >
                                <BaseInputNumber
                                        v-model="form.currentVersion"
                                        disabled
                                />
                            </a-form-model-item>
                        </a-col>
                        <a-col
                                v-if="id != ''"
                                :md="8"
                                :sm="8"
                        >
                            <a-form-model-item
                                    label="报审表编号"
                                    prop="reviewCode"
                            >
                                <BaseInput
                                        v-model="form.reviewCode"
                                        disabled
                                />
                            </a-form-model-item>
                        </a-col>
                        <a-col
                                :md="8"
                                :sm="8"
                        >
                            <a-form-model-item
                                    label="文件编码"
                                    prop="fileCode"
                            >
                                <BaseInput
                                        v-model="form.fileCode"
                                        disabled
                                />
                            </a-form-model-item>
                        </a-col>
                        <a-col
                                :md="8"
                                :sm="8"
                        >
                            <a-form-model-item
                                    label="编制人员"
                                    prop="compiler"
                            >
                                <SelectPersonByProject
                                        :id="form.branchCompanyId"
                                        v-model="form.compiler"
                                        :project-id="form.projectId"
                                        :show-search="true"
                                        disabled
                                        :is-edit="type !== 'view'"
                                        option-label-prop="children"
                                        mode="combobox"
                                />
                            </a-form-model-item>
                        </a-col>
                        <a-col
                                :md="24"
                                :sm="24"
                        >
                            <a-form-model-item label="方案概况">
                                <BaseTextarea
                                        v-model="form.programOverview"
                                        disabled
                                        :auto-size="{ minRows: 2, maxRows: 6 }"
                                />
                            </a-form-model-item>
                        </a-col>
                        <a-col
                                :md="8"
                                :sm="8"
                        >
                            <a-form-model-item
                                    label="正文页数"
                                    prop="bodyPages"
                            >
                                <BaseInputNumber
                                        v-model="form.bodyPages"
                                        :max="10000"
                                        disabled
                                />
                            </a-form-model-item>
                        </a-col>
                        <a-col
                                :md="8"
                                :sm="8"
                        >
                            <a-form-model-item
                                    label="附件页数"
                                    prop="attachmentPages"
                            >
                                <BaseInputNumber
                                        v-model="form.attachmentPages"
                                        :max="10000"
                                        disabled
                                />
                            </a-form-model-item>
                        </a-col>
                        <a-col
                                :md="8"
                                :sm="8"
                        >
                            <a-form-model-item label="是否涉及重大费用诉求">
                                <a-switch
                                        v-model="form.whetherMajorExpense"
                                        default-checked
                                        disabled
                                />
                            </a-form-model-item>
                        </a-col>
                        <a-col
                                :md="8"
                                :sm="8"
                        >
                            <a-form-model-item label="是否为专业分包方案">
                                <a-switch
                                        v-model="form.whetherProfessionalSubcontracting"
                                        default-checked
                                        disabled
                                />
                            </a-form-model-item>
                        </a-col>
                        <a-col   v-if="form.whetherProfessionalSubcontracting"
                                 :md="8"
                                 :sm="8"
                        >
                            <a-form-model-item
                                    label="分包类型"
                                    prop="subTypeId"
                                    required
                            >
                                <a-select
                                        v-model="form.subTypeId"
                                        placeholder="请选择"
                                        disabled
                                >
                                    <a-select-option
                                            v-for="item in subcontractType"
                                            :key="item.id"
                                            :value="item.id"
                                    >
                                        {{ item.name }}
                                    </a-select-option>
                                </a-select>
                            </a-form-model-item>
                        </a-col>
                        <a-col
                                v-if="form.whetherProfessionalSubcontracting"
                                :md="8"
                                :sm="8"
                        >
                            <a-form-model-item
                                    label="计划讲评时间"
                                    prop="evaluationDate"
                            >
                                <a-date-picker
                                        v-model="form.evaluationDate"
                                        disabled
                                />
                            </a-form-model-item>
                        </a-col>
                        <a-col
                                :md="8"
                                :sm="8"
                        >
                            <a-form-model-item
                                    label="分公司方案审核师"
                                    prop="branchAuditorUserId"
                                    required
                            >
                                <a-select
                                        v-model="form.branchAuditorUserId"
                                        placeholder="请选择"
                                        disabled
                                >
                                    <a-spin v-if="fetching" slot="notFoundContent" size="small" />
                                    <a-select-option
                                            v-for="item in branchCompanyData"
                                            :key="item.userId"
                                            :value="item.userId"
                                    >
                                        {{ item.employeeName }}{{item.phone}}
                                    </a-select-option>
                                </a-select>
                            </a-form-model-item>
                        </a-col>
                        <!-- 施组、A、B类方案 -->
                        <a-col
                                :md="8"
                                :sm="8"
                                v-if="schemeSzAB"
                        >
                            <a-form-model-item
                                    label="公司方案审核师"
                                    prop="comAuditorUserId"
                                    required
                            >
                                <a-select
                                        v-model="form.comAuditorUserId"
                                        placeholder="请选择"
                                        disabled
                                >
                                    <a-select-option
                                            v-for="item in companyData"
                                            :key="item.userId"
                                            :value="item.userId"
                                    >
                                        {{ item.employeeName }}{{item.phone}}
                                    </a-select-option>
                                </a-select>
                            </a-form-model-item>
                        </a-col>
                        <a-col
                                :md="8"
                                :sm="8"
                        >
                            <a-form-model-item
                                    label="预计开始实施时间"
                                    prop="expectedStartDate"
                            >
                                <a-date-picker
                                        v-model="form.expectedStartDate"
                                        disabled
                                />
                            </a-form-model-item>
                        </a-col>
                        <a-col
                                :md="8"
                                :sm="8"
                        >
                            <a-form-model-item
                                    label="预计实施结束时间"
                                    prop="expectedEndDate"
                            >
                                <a-date-picker
                                        v-model="form.expectedEndDate"
                                        disabled
                                />
                            </a-form-model-item>
                        </a-col>
                        <a-col :md="24" :sm="24">
                            <a-form-model-item label="附件上传">
                                <fileTable
                                        :business-code="'TM05'"
                                        :file-info="form.changeFileInfo2"
                                        disabled
                                        :fileTalbe="fileTalbe1"
                                />
                            </a-form-model-item>
                        </a-col>
                    </a-row>
                </a-form-model>
            </div>
        </a-card>
    </a-spin>
</template>

<script>
  import SelectPersonByProject from '@/components/Select/SelectPersonByProject'
  import TitleName from '@/components/TitleName/index.vue'
  import fileTable from './fileTable.vue'
  import SelectTreeSubItem from '@/components/Select/SelectTreeSubItem'
  import { fileInfoVOListColumns} from '../model.js'
  import SelectProjectType from '@/components/Select/SelectProjectType' // 工程类别
  import { Ellipsis } from '@/components'
  import { listOption } from '@/api/technical/approvalPlan'
  import { getReviewerList } from '@/api/technical/review'
  import { getOption } from '@/api/technical/approval'
  const fileColumns = [
    {
      title: '序号',
      width: '65px',
      scopedSlots: { customRender: 'serial' }
    },
    {
      title: '文件名称',
      width: '200px',
      dataIndex: 'fileName'
    },
    {
      title: '文件',
      dataIndex: 'fileList'
    },
    {
      title: '操作',
      dataIndex: 'operation',
      width: '120px',
      scopedSlots: { customRender: 'operation' }
    }
  ]
  export default {
    name: 'baseInfo',
    components: {
      TitleName,
      SelectPersonByProject,
      fileTable,
      SelectTreeSubItem,
      SelectProjectType,
      Ellipsis
    },
    data() {
      return {
        companyData: [],
        branchCompanyData: [],
        typeOption: [],
        conclusionData: [],
        subcontractType: [],
        fileColumns,
        fileInfoVOListColumns,
        htmlData: '',
        htmlDatas: '',
        loading: {
          isDraft: false,
          isSubmit: false
        },
        selectionSchemeVisible:false,
        fileTalbe1: [
          { id:1,fileName: '施工方案电子版', fileList: [] },
          { id:2,fileName: '相关图纸变更', fileList: [] },
          { id:3,fileName: '相关会签表', fileList: [] },
          { id:4,fileName: '其他', fileList: [] },
        ],
        planItemList: [], // 计划项列表
        type: '',
        id: '',
        historicalData:false, //是否历史数据
        disabled: false,
        tableData: [],
        ScoreTableData: [],
        selectedRowKeys: '',
        selectedRows: '',
        totalScore: '',
        result: '',
        vetoHeaderId: '',
        columnsScore: [],
        columns: [],
        scoreInformation: '',
        scorecount: '',
        //获取流程配置值
        processConfig: null,
        //点击提交发送流程配置值
        setProcessConfig: null,
        businessId: null,
        allDisable:false, //禁用所有
        dangerousProjectVisible:false,
        projectType:'1', //危大工程范围传参，A 传1 超危大工程，B 传2 危大工程
        goodBusDTO:{},
        sendUser: [],//实施责任人列表
        noticeType:null,  //待办编码
        fetching:false,
        businessType:null,
      }
    },
    props: {
      form: {
        type: Object,
        default() {
          return {
            changeFileInfo2: [],
            reportingType: '0',
            compiler: '',
            branchComId: '',
            projectId: '',
            fileInfoVOList: [],
            programTypeId: '',
            schemeName: '',
            projectQualityTypeId:null,
            newFileIds:{},
            dangerDangerDTOS:[], //危大工程范围数据
          }
        }
      }
    },
    watch: {
      'type':{
        immediate: true,
        async handler(val) {
          if(val == 'change'){
            //获取通过获取流程配置值
            this.processConfig = await this.$getConfigFn('technology_construction_plan_a_two');
          }
        }
      },
      'form.programTypeId':{
        immediate: true,
        handler(val) {
          if (val) {
            if(val == '634285858551369728'){
              this.projectType = '1';
            }else if(val == '634285886040838144'){
              this.projectType = '2';
            }
          }
        }
      },
    },
    computed: {
      // 是否是业务待办查看处理信息
      resolveInfo: {
        get() {
          return this.$route.query?.resolveInfo === 'true'
        },
        set() {}
      },
      editable() {
        return this.$route.query.type == 'add' || this.$route.query.type == 'edit'
      },
      editableVersionNumber() {
        let flag  = false;
        if(this.type == 'add'){
          flag = false;   //新增可以编辑
        }
        else if(this.type == 'edit'){
          if(this.form.versionNumber*1>1){  //编辑时，且版本大于1不能编辑
            flag = true
          }else{
            flag = false
          }
        }else{   //其他情况不能修改
          flag = true
        }
        return flag;
      },
      addtable() {
        return this.$route.query.type == 'add';
      },
      isSchemeCategoryA(){
        return this.$route.query.isSchemeCategoryA;
      },
      changeEditable(){
        let type = this.$route.query.type,isSchemeCategoryA = this.$route.query.isSchemeCategoryA,
          flag = false;
        if(type == 'view' || isSchemeCategoryA){    //查看，或者为方案A，
          flag = true
        }else if(type == 'changeDetail' && !isSchemeCategoryA){  //变更并且方案不为A
          flag = false
        }
        else if(type == 'change'){
          flag = true
        }else{
          flag = false
        }
        return flag;
      },
      //方案是否是A,B，施组
      schemeSzAB(){
        let programTypeId = this.form.programTypeId,
          schemeArr = ['634286036096258048','634285858551369728','634285886040838144'],  //施组，A,B
          flag = schemeArr.includes(programTypeId);
        return flag
      },
      //方案是否是A,B
      schemeAB(){
        let programTypeId = this.form.programTypeId,
          schemeArr = ['634285858551369728','634285886040838144'], //A,B
          flag = schemeArr.includes(programTypeId);
        return flag
      }
    },
    created() {
      this.type = this.$route.query.type;
      this.id = this.$route.query.id || '';
      this.historicalData = this.$route.query.historicalData || false;   //是否是点击历史版本查看历史数据
        this.id = this.$route.query.id || '';
      let type = this.$route.query.type;
      this.allDisable = type == 'allDisable';
      this.listOption()
      this.getReviewerListFn()
    },
    methods: {
      selectOrg(val) {
        this.fetching = true;
        this.form.branchComId = val[val.length - 2].orgId
        this.getOption()
        let branchCompanyOrgId = val[0].orgId;   //获取分公司orgiD
        this.getBranchCompanyListFn(branchCompanyOrgId)
      },
      getOption() {
        const { projectId } = this.form
        if (!projectId) return
        const params = {
          projectId: projectId
        }
        getOption(params).then((res) => {
          if (res.code === 200) {
            this.planItemList = res.data
          }
        })
      },
      //获取公司审核师
      getReviewerListFn(){
        let params = {
          orgId:'53085e2c9f1f4685801ef31994f57c49',   //直属机关orgId
          pageNo:1,
          pageSize:10000
        }
        getReviewerList(params).then((res)=>{
          if(res.code == '200'){
            this.companyData = res.data
          }
        })
      },
      //获取分公司审核师
      getBranchCompanyListFn(org){
        this.branchCompanyData = [];
        let params = {
          orgId:org,   //直属机关orgId
          pageNo:1,
          pageSize:10000
        }
        getReviewerList(params).then((res)=>{
          if(res.code == '200'){
            this.branchCompanyData = res.data
            this.fetching = false;
          }
        })
      },
      listOption() {
        listOption({ type: '5' }).then((res) => {
          this.typeOption = res.data || [];
          if(this.typeOption.length){
            this.typeOption.map((item)=>{
              item.label = item.name;
              item.value = item.id;
            })
          }
        })
        listOption({ type: '8' }).then((res) => {
          this.conclusionData = res.data
        })
        listOption({ type: '15' }).then((res) => {
          this.subcontractType = res.data
        })
      },
    }
  }
</script>

<style lang="less">
    @deep: ~'>>>';
    .technical-use-component {
        padding: 0 !important;
        .content-bx{
            height: auto !important;
            padding-right: 0 !important;
        }
    }
    .foot-btn {
        display: flex;
        justify-content: flex-end;
    }
    .radio-box {
        .ant-radio-wrapper {
            position: static !important;
        }
        .ant-radio-group {
            margin-top: 3% !important;
            display: flex;
        }
    }
    .title {
        border-left: 4px solid #1890ff;
        font-weight: bold;
        font-size: 14px;
        margin-bottom: 20px;
        padding-left: 10px;
        height: 18px;
        line-height: 20px;
        margin-left: 20px;
        margin-top: 20px;
    }
    .customtable {
        width: 100%;
        border: 1px solid gainsboro;

        thead {
            background: rgb(244, 244, 244);

            th {
                padding: 10px;
                border: 1px solid gainsboro;
            }
        }

        tbody {
            td {
                padding: 10px;
                border: 1px solid gainsboro;
            }
        }
    }
    .table-page-search-wrapper{
        .requireX::before{
            display: inline-block;
            color: #f5222d;
            font-size: 14px;
            font-family: SimSun, sans-serif;
            line-height: 1;
            content: '*';
        }
        .planSelection-class{
            .ant-form-item-children{
                position: relative;
                display: flex;
                .BaseInput-container{
                    width: 91%;
                }
            }
            .ant-btn{
                position: absolute;
                right: -40px;
                top: 0;
                flex: 1;
                z-index: 100;
            }
        }
        .ant-input-disabled{
            background-color: #F5F5F5!important;
            border-color:#F5F5F5!important;
        }
    }
    .dangerProjectType{
        max-height: 100px;
        overflow: scroll;
    }
</style>